﻿using Anke.SHManage.BLL;
using Anke.SHManage.MSSQLDAL;
using Anke.SHManage.MSSQLDAL.TJDAL;
using Anke.SHManage.Utility;
using Microsoft.Reporting.WebForms;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;



namespace Anke.SHManage.Web.Reports
{
   
    public partial class TJ_JLKWebForm : System.Web.UI.Page
    {
        private string centerName;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitPage();
            }

        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindReportDataSource();

        }
        private void InitPage()
        {
            this.StartDate.Text = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd 07:30:00");
            this.EndDate.Text = DateTime.Now.ToString("yyyy-MM-dd 07:30:00");

            //引用DropDownListBLL的 GetCenterOnaspx获取分中心，GetStationOnaspx获取分站。使用ControlHelper.SetDropDownList赋值给DropDownList
            //DropDownListBLL dbll = new DropDownListBLL();
            //ControlHelper.SetDropDownList(DropDownList_Center, dbll.GetCenterOnaspx(), "-1");//分中心
            //ControlHelper.SetDropDownList(DropDownList_Station, dbll.GetStationOnaspx("-1"), "-1");//分站

            BindReportDataSource();
        }
        protected void BindReportDataSource()
        {
            DateTime beginTime = Convert.ToDateTime(this.StartDate.Text);
            DateTime endTime = Convert.ToDateTime(this.EndDate.Text);
            string txtCenter = Convert.ToString(this.Center.Text);
            string stationID = (this.Station.Text).ToString();
            string start1 = beginTime.ToString();
            string end1 = endTime.ToString();
            if (txtCenter != "")
            { centerName = new TJDAL().GetNameByID(txtCenter); }
            else
            {
                centerName = "全中心";
            }
            // string txtCenter = Convert.ToString(this.DropDownList_Center.SelectedValue);
            //// string txtCenter = Convert.ToString(DropDownList_Center.Text);
            // string stationID = Convert.ToString(this.DropDownList_Station.SelectedValue);
            this.ReportViewer1.LocalReport.DataSources.Clear();
            this.ReportViewer1.LocalReport.ReportPath = Server.MapPath(@"~/Reports/TJ_JLK.rdlc");
            Microsoft.Reporting.WebForms.ReportParameter st = new Microsoft.Reporting.WebForms.ReportParameter("StartTime", start1);
            Microsoft.Reporting.WebForms.ReportParameter ed = new Microsoft.Reporting.WebForms.ReportParameter("EndTime", end1);
            Microsoft.Reporting.WebForms.ReportParameter name = new Microsoft.Reporting.WebForms.ReportParameter("Center", centerName);
            this.ReportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { st, ed, name });
            TJDAL dal = new TJDAL();
            //DataTable dtdl = dal.Get_TJ_JLK(beginTime, endTime, txtCenter);
            DataTable dtdl = dal.Get_TJ_JLK(beginTime, endTime, txtCenter,stationID);
            this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForTJ_JLK", dtdl));
            this.ReportViewer1.LocalReport.Refresh();
        }
    }
}